<?php
/*
 * @Author: lokei
 * @Date: 2022-12-30 17:28:40
 * @LastEditors: lokei
 * @LastEditTime: 2022-12-31 12:27:53
 * @Description: 
 */
namespace App\Http\Controllers\Widget;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Widget\ThemePersonModel;
use Illuminate\Http\Request;

class PersonController extends Controller {
    public function get() {
        $theme = ThemePersonModel::first();
        if(is_null($theme)) {
            $theme = new ThemePersonModel();
            $theme->save();
        }
        $res = ResultTool::success();
        $res['data']['theme'] = $theme;
        return $res;
    }

    public function getNav() {
        $theme = ThemePersonModel::first();
        if(is_null($theme)) {
            $theme = new ThemePersonModel();
            $theme->save();
        }
        $res = ResultTool::success();
        $res['data']['theme'] = $theme;
        return $res;
    }

    public function updateNav(Request $request) {
        $theme = ThemePersonModel::first();
        $theme->nav_on = eval("return " . $request->input('nav_on') . ";") ? '1' : '0';
        if($request->input('nav_amount_line') != null) {
            $theme->nav_amount_line = $request->input('nav_amount_line');
        }
        $theme->save();
        return ResultTool::success();
    }

    public function getList() {
        $theme = ThemePersonModel::first();
        if(is_null($theme)) {
            $theme = new ThemePersonModel();
            $theme->save();
        }
        $res = ResultTool::success();
        $res['data']['theme'] = [
            'list_on' => $theme->list_on
        ];
        return $res;
    }

    public function updateList(Request $request) {
        $theme = ThemePersonModel::first();
        $theme->list_on = eval("return " . $request->input('list_on') . ";") ? '1' : '0';
        $theme->save();
        return ResultTool::success();
    }
}